package com.easygo.service.impl;

import com.easygo.Dao.GoodsDao;
import com.easygo.service.GoodService;
import com.xuexi.easygo.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class GoodServiceImpl implements GoodService {

    @Autowired
    GoodsDao goodsDao;

    @Override
    public Goods SaveDocument(Goods goods) {
        return goodsDao.save(goods);
    }

    @Override
    public Iterable<Goods> SaveDocuments(List<Goods> goods) {
        return goodsDao.saveAll(goods);
    }

    @Override
    public void saveDocumentById(Goods goods) {
        goodsDao.save(goods);
    }

    @Override
    public Goods getDocumentsById(Long id) {
        Optional<Goods> good = goodsDao.findById(id);
        return good.get();
    }

    @Override
    public void deleteDocumentById(Long id) {
        goodsDao.deleteById(id);
    }

    @Override
    public void deleteAll() {
        goodsDao.deleteAll();
    }
}
